package com.sphd.Restaurant.fragments;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.sphd.Restaurant.R;
import com.sphd.Restaurant.activity.LoginActivity;
import com.sphd.Restaurant.adapters.MyViewPagerAdapter;
import com.sphd.Restaurant.base.BaseFragment;
import com.sphd.Restaurant.fragments.orderFragments.InOrdersFragment;
import com.sphd.Restaurant.fragments.orderFragments.OutOrdersFragment;
import com.sphd.Restaurant.utils.Constants;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Hu on 2016/9/25.
 */

public class OrderFragment extends BaseFragment {


    InOrdersFragment inOrdersFragment;
    OutOrdersFragment outOrdersFragment;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.tabs)
    TabLayout tabs;
    @BindView(R.id.vp_two)
    ViewPager vpTwo;
    @BindView(R.id.fab)
    Button fab;
    @BindView(R.id.tv_show)
    TextView tvShow;
    List<Fragment> fragmentList;
    MyViewPagerAdapter allRestsAdapter;

    @Override
    public int getLayout() {
        return R.layout.fragment_in_or_out;
    }

    @Override
    public void initViews(View view) {
        ButterKnife.bind(this, view);
        initview();
    }

    private void initview() {
        fragmentList = new ArrayList<>();
        inOrdersFragment = new InOrdersFragment();
        outOrdersFragment = new OutOrdersFragment();
        fragmentList.add(inOrdersFragment);
        fragmentList.add(outOrdersFragment);
        String[] titles = {"店内", "外卖"};
        allRestsAdapter = new MyViewPagerAdapter(getChildFragmentManager(), fragmentList, titles);
        vpTwo.setAdapter(allRestsAdapter);
        tabs.setupWithViewPager(vpTwo);
        if (getBoolean(Constants.ISLOGIN)) {
            tvShow.setVisibility(View.GONE);
            fab.setVisibility(View.GONE);
        }
    }

    @OnClick(R.id.fab)
    public void onClick() {
        startActivity(LoginActivity.class);
    }
}
